import { Component,OnInit } from '@angular/core';
import {Hero} from "../../class/hero";
import {HeroService} from "../../service/hero.service.service";
import { Router }   from '@angular/router';

@Component({
  selector: 'my-heros',
  templateUrl: './heros.component.html',
  styleUrls: ['./heros.component.css'],
  providers: [HeroService]
})

export class HerosComponent implements OnInit{
  constructor(private router: Router,private heroSerive:HeroService){

  }
  ngOnInit(){
    this.getHero();
  }
  title = 'Tour of Heroes';
  heroes : Hero[];
  selectedHero:Hero;
  getHero():void{
    this.heroSerive.getHerosSlowly().then(heros=>this.heroes=heros);
  }
  onSelected(hero:Hero):void{
    this.selectedHero = hero;
  }
  gotoDetail():void{
    this.router.navigate(['/detail',this.selectedHero.id]);
  }
}
